package com.ruoyi.pims.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pims.domain.EduMajor;
import com.ruoyi.pims.service.IEduMajorService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 专业信息Controller
 * 
 * @author ruoyi
 * @date 2025-04-30
 */
@Controller
@RequestMapping("/pims/major")
public class EduMajorController extends BaseController
{
    private String prefix = "pims/major";

    @Autowired
    private IEduMajorService eduMajorService;

    @RequiresPermissions("pims:major:view")
    @GetMapping()
    public String major()
    {
        return prefix + "/major";
    }

    /**
     * 查询专业信息列表
     */
    @RequiresPermissions("pims:major:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EduMajor eduMajor)
    {
        startPage();
        List<EduMajor> list = eduMajorService.selectEduMajorList(eduMajor);
        return getDataTable(list);
    }

    /**
     * 导出专业信息列表
     */
    @RequiresPermissions("pims:major:export")
    @Log(title = "专业信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EduMajor eduMajor)
    {
        List<EduMajor> list = eduMajorService.selectEduMajorList(eduMajor);
        ExcelUtil<EduMajor> util = new ExcelUtil<EduMajor>(EduMajor.class);
        return util.exportExcel(list, "专业信息数据");
    }

    /**
     * 新增专业信息
     */
    @RequiresPermissions("pims:major:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存专业信息
     */
    @RequiresPermissions("pims:major:add")
    @Log(title = "专业信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EduMajor eduMajor)
    {
        return toAjax(eduMajorService.insertEduMajor(eduMajor));
    }

    /**
     * 修改专业信息
     */
    @RequiresPermissions("pims:major:edit")
    @GetMapping("/edit/{majorId}")
    public String edit(@PathVariable("majorId") Long majorId, ModelMap mmap)
    {
        EduMajor eduMajor = eduMajorService.selectEduMajorByMajorId(majorId);
        mmap.put("eduMajor", eduMajor);
        return prefix + "/edit";
    }

    /**
     * 修改保存专业信息
     */
    @RequiresPermissions("pims:major:edit")
    @Log(title = "专业信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EduMajor eduMajor)
    {
        return toAjax(eduMajorService.updateEduMajor(eduMajor));
    }

    /**
     * 删除专业信息
     */
    @RequiresPermissions("pims:major:remove")
    @Log(title = "专业信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(eduMajorService.deleteEduMajorByMajorIds(ids));
    }
}
